#include "mcu_timer.h"
#include "mcu.h"



void Tim1_Init()     
{
    T12CON &= 0xfc;
    T12CON |= (1<<1)|(1<<0);        /* 选择时钟*/
    T1STA = (TIM1_CLKDIV<<4);       /*输入时钟预分频比选择1:1 ( 16MHz  __ T = 0.0625us)*/
    TMR1H = 0x00;
    TMR1L = 0x00;
    TMR1IF = 0;
    PWMCON1 &= 0xcc;
    PWMCON1 |= (TIM1_CH1_PORT<<5)|(TIM1_CH0_PORT<<4)|(TIM1_CH1_DIR<<1)|(TIM1_CH0_DIR<<0);   /*默认输出引脚和极性*/
    PWMCON0 &= 0xcc;
    PWMCON0 |= (TIM1_CH1_EN<<5)|(TIM1_CH0_EN<<4)|(1<<1)|(1<<0);
    _HTim1_SetPWM_CYCLE(TIM1_CYCLE);
#if (MCU_PIFB1_INIT&TIM1IE_EN)
    PWMAIE = 0;     // 临时关闭中断
#endif
    TMR1ON = 1; /*启动/停止??*/
    PWMAF = 0;
    while (PWMAF == 0);
    PWMAF = 0;
#if (MCU_PIFB1_INIT & TIM1IE_EN)
    PWMAIE = 1;     // 恢复开启中断
#endif
    TMR1ON = TIM1_RUN; /*启动/停止??*/
}


void Tim2_Init()      
{
    T12CON &= 0xf3;
    T12CON |= (1<<3)|(1<<2); /* 选择时钟*/                                
    T2STA = (TIM2_CLKDIV<<4);		  /*输入时钟预分频比选择1:1 ( 16MHz  __ T = 0.0625us)*/   
    TMR2H = 0x00;    
    TMR2L = 0x00;    
    TMR2IF = 0;
    PWMCON1 &= 0x33;
    PWMCON1 |= (TIM2_CH1_PORT<<7)|(TIM2_CH0_PORT<<6)|(TIM2_CH1_DIR<<3)|(TIM2_CH0_DIR<<2);/*默认输出引脚和极性*/
    PWMCON0 &= 0x33;
    PWMCON0 |= (TIM2_CH1_EN<<7)|(TIM2_CH0_EN<<6)|(1<<3)|(1<<2);
    _HTim2_SetPWM_CYCLE(TIM2_CYCLE);     
#if (MCU_PIFB1_INIT & TIM2IE_EN)     
    PWMBIE = 0;     // 临时关闭中断
#endif       
    TMR2ON = 1; /*启动/停止??*/
    PWMBF = 0;
    while (PWMBF == 0);
    PWMBF = 0;
#if (MCU_PIFB1_INIT & TIM2IE_EN) 
    PWMBIE = 1;     // 恢复开启中断
#endif
    TMR2ON = TIM2_RUN; /*启动/停止??*/
}





